package org.train.entity;

import com.fasterxml.jackson.annotation.JsonGetter;
import lombok.Data;

import java.util.Date;

// 合同总览使用的对象
@Data
public class ProjectInfoVo{
    private Integer id; // 项目id
    private String contractName; // 项目名
    private Date contractStartTime;
    private Date contractEndTime;
    private String projectLeader;
    private Double contractAmount = 0.0;
    private Double totalBilling = 0.0; // 累计开票
    private Double annualBilling = 0.0; // 当年开票
    private Double totalExpenditure = 0.0; // 累计支出
    private Double annualExpenditure = 0.0; // 当年支出
    private Double totalFundsReceived = 0.0; // 累计回款

    @JsonGetter("receivable")
    public Double getReceivable(){
        // 当年应收=累计开票-累计回款
        return totalBilling - totalFundsReceived;
    }
    @JsonGetter("annualGrossProfit")
    public Double getAnnualGrossProfit(){
        // 当年毛利=年度开票-年度支出
        return annualBilling - annualExpenditure;
    }
    @JsonGetter("profitRate")
    public Double getProfitRate(){
        // 利润率=(累计开票-累计支出)/累计开票
        if(totalBilling == 0){
            return 0.0;
        }
        return (totalBilling - totalExpenditure) / totalBilling;
    }

    public ProjectInfoVo assignProjectPo(ProjectPo po){
        this.setId(po.getId());
        this.setContractName(po.getContractName());
        this.setContractStartTime(po.getContractStartTime());
        this.setContractEndTime(po.getContractEndTime());
        this.setContractAmount(po.getContractAmount());
        this.setProjectLeader(po.getProjectLeader());
        return this;
    }
}
